<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
<input type="hidden" name="projId" id="projId" value="${projId }"/>
<input type="hidden" name="projName" id="projName" value="${projName }"/>
    <section class="content-header">
        <h1>已添加医疗机构</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
            <li class="active"><a href="#">项目管理</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">                
                 <div class="input">
                        <div class="textalign1">医疗机名称：</div>
                        <div class="boxinput">
                            <input type="text" class="textinput" id="hospName" name="hospName" placeholder="医疗机名称/<spring:message code="message.listForm.pinYinMa"/>" />
                        </div>
                        <!-- <div class="textalign1">医疗机构编码:</div>
                        <div class="boxinput">
                            <input type="text" class="textinput" id="hospCode" name="hospCode" placeholder="医疗机构编码" />
                        </div> -->
                        <!-- <div class="textalign">医疗机分类：</div>
                        <div class="boxinput">
                            <select  id="hospClassify" name="hospClassify" class="textinput"></select>
                        </div> -->
                        <div class="textalign" >所属地区：</div>
                         <div class="boxinput">
                                 <table style="width:100%;">
                                   <tr>
                                      <td style="width:33%">
                                        <select class="textinput" id="area1" name="area1" disabled="disabled">
                                           <option value="${area.areaId }">${area.areaName }</option>
                                        </select>
                                      </td>
                                      <td style="width:33%">   
                                        <select class="textinput" id="area2" name="area2"></select>
                                        </td>
                                      <td style="width:33%">
                                        <select class="textinput" id="area3" name="area3"> </select>
                                      </td>
                                   </tr> 
                                </table>
                            </div>    
                          <div class="textalign">是否零差率医院：</div>
			                    <div class="boxinput">
		                        <select class="textinput" id="hospClassifys" name="hospClassifys">
		                        	<option value="">请选择</option>
		                            <option value="2">是</option>
		                            <option value="1">否</option>
		                        </select>
		                    	</div>
                   </div>
                   <div class="input">
                            <div class="textalign1">状态：</div>
                            <div class="boxinput">
                                <select id="status" name="status" class="textinput">
                                    <option value="">请选择</option>
                                    <option value="1">启用</option>
                                    <option value="0">停用</option>
                                </select>
                            </div>   
                            
		                    <div class="textalign"><spring:message code="message.lable.yiLiaoJiGouDengJi"/>：</div>
		                    <div class="boxinput">
		                         <select class="textinput"  id="hospType"  name="hospType"></select>
		                    </div>  
		                                
                            <div class="textalign" >
                                <button  id="selectSerch"  type="button" onclick="gridSerch()" class="btn btn-success btn-sm">查 询</button>
                            </div>
                     </div>
                
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>

        <div class=" box box-warning bottongroup">
            <label class="btn btn-default btn-sm" onclick="batchChangeStatus(1)">启 用</label>
            <label class="btn btn-default btn-sm" onclick="batchChangeStatus(0)">停 用</label>
            <a href="${ctx }/bidProject/toPurList.html" class="btn btn-default btn-sm">返 回</a>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
        $(function () {
        	
        	//加载页面光标在名字框内，位于第一个
            $("#hospName").focus();
            
          //绑定回车     id="selectSerch"   
            $('#hospName,#hospCode,#hospClassify,#hospClassifys,#hospType,#area1,#area2,#area3,#status').bind('keydown', function(event) {
                if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
                    $('#selectSerch').click();
                }
            }); 

            $("#area2").HNSelect({
            	parent_selector: "#area1",  url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID",defaultText: "<option value=''>请选择</option>",
                func: function () {
                    $("#area3").HNSelect({
                        parent_selector: "#area2", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID", defaultText: "<option value=''>请选择</option>",
                        		
                    });
                }
            });
        	
            $("#gridlist").jqGrid({
                url: "getAddedBidProjectHospsList.html",
                mtype: "POST",
                datatype: "json",
                postData: { "projId" : "${projId}"},
                autowidth: true,
                height: 255,
                colNames: [
                           'projHospId',
                           'hospId',
                           '医疗机构编码',
                           '医疗机构名称',
                           '所属地区', 
                           '医疗机构分类', 
                           '医疗机构属性',
                           '医疗机构类型',
                           '医疗机构等级', 
                           '组织机构代码' , 
                           '状态' 
                           ],
                colModel: [
                    { name: 'projHospId', key:true,hidden:true, width: 40, align: 'center' ,sortable: false},
                    { name: 'hospId', key:true,hidden:true,width: 40, align: 'center' ,sortable: false},
                    { name: 'hospCode', width: 80 , hidden:true,align:"center",sortable: false,
                    	formatter:function(cellvalue, options, row){ 
                    		return "<a href=\"javascript:$.HN.dialog.opendialog('"+row.hospId+"','医疗机构详情','${pageContext.request.contextPath}/stdHospInfo/hospInfoDetail.html?hospId="+row.hospId+"','800px','400px',function operResult(val){return operResult;})\">"+cellvalue+"</a>"
                    				}
                    },
                    { name: 'hospName', width: 150, align: 'left' ,sortable: false},
                    { name: 'arfullname', width: 80, align: 'center' ,sortable: false},
                    { name: 'hospClassifyName', width: 90, align: 'center' ,sortable: false,hidden:true},
                    { name: 'hospClassifyName', width: 90, align: 'center' ,sortable: false,
                    	formatter : function(val, opts, rowdata) {
                            var strSta = "";
                            if(rowdata.hospClassify == 1){
                                strSta += "县级及县级以上医院";
                            }else if(rowdata.hospClassify==2){
                                strSta += "基层医院";
                            }
                            return strSta;
                        }},
                    { name: 'hosptype.hospType', width: 80, align: 'center' ,sortable: false},
                    { name: 'hsopLevelName', width: 60, align: 'center' ,sortable: false},
                    { name: 'orgCode', width: 60, hidden:true,align: 'center' ,sortable: false},
                    { name: 'status', width : 30, align : 'center', sortable : false,
                    	cellattr:function (rowId, val, rawObject, cm) {
                            if(val == '停用'){
                                return 'style="color:red"';
                            }
                        },
                    	formatter : function(val, opts, rowdata) {
							if (rowdata.status == 1 ) {
								return "启用";
							} else if (rowdata.status == 0) {
								return "停用";
							}
						}
                    }
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                multiselect: true,
                pager: "#gridpage",
                viewrecords: true,
                caption: "${proName} - 已添加医疗机构 ",
              //序号宽度自动变化
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                jsonReader: {
                    repeatitems: false  
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
			$("#gridlist").jqGrid("setGridHeight", create());
			$(window).trigger("resize");
			
            $("#hospClassify").HNSelect({
                url: "${pageContext.request.contextPath}/selectController/getDicSys.html", data: { ID: '113' },defaultselect:'${form.patternType}',  defaultText: "<option value=''>请选择</option>",
            });
            $("#hospType").HNSelect({ 
                url: "${ctx}/selectController/getDicSys.html", 
                data: { 'ID' : "002" },
                defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                defaultselect: "",
            });
           
        });
        function gridSerch() {
        	var hospCode = $.trim($("#hospCode").val());
        	var hospName = $.trim($("#hospName").val());
        	var hospClassify = $.trim($("#hospClassify").val());
        	var hospClassifys = $("#hospClassifys").val();
            var hospType = $("#hospType").val();
        	var area = $.trim($("#area3").val());
        	var	father = $.trim($("#area2").val());
        	var	status = $.trim($("#status").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"hospCode":hospCode,
    	        		"hospName":hospName,
    	        		"hospClassify":hospClassify,
    	        		"hospClassifys":hospClassifys,
    	        		"hospType":hospType,
    	        		"areaId":area,
    	        		"status":status,
    	        		"fahterId":father,
    	        		"projId":$("#projId").val()},
    	        		page:1
    	    }).trigger("reloadGrid"); //重新载入  
    	}
        
        
          function changeStatus(hospId, projHospId, status) {
    		$.post("changeHospStatus.html", {
    			"projHospId" : projHospId,
				"hospId" : hospId,
    			"status" : status
    		}, function(success) {
    			if (success) {
    				gridSerch();
    				$.HN.message.alert("操作成功！", "消息", "success");
    			} else {
    				$.HN.message.alert("操作失败！", "消息", "error");
    			}
    		}, "json")
    	} 
         
        function batchChangeStatus(status) {
			var msg = "";
			if (status == "0") {
				msg = "停用";
			} else if (status == "1") {
				msg = "启用";
			}
			
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的医疗机构！", "消息", "warn");
    			return;
    		}
			
    		$.HN.message.confirm('确定' + msg + '吗？', '', '').on(function (e) {
    			if (e) {
    				var list = [];
    	    		for (var i=0; i<rowIds.length; i++) {
    	    			var rowdata = $("#gridlist").jqGrid('getRowData', rowIds[i]);
    	    			var rowId = rowdata.projHospId;
						var hospId = rowdata.hospId;
						var projId = $("#projId").val();
    	    			list.push({"projHospId":rowId, "status":status, "projId":projId, "hospId":hospId});
    	    		}
    	    		$.post("batchChangeHospStatus.html", {"array" : json.jsonToString(list)
    	    		}, function(success) {
    	    			if (success) {
    	    				gridSerch();
    	    				$.HN.message.alert("操作成功！", "消息", "success");
    	    			} else {
    	    				$.HN.message.alert("操作失败！", "消息", "error");
    	    			}
    	    		}, "json")
    			}
    		})
    	}
    </script>
</body>
</html>
